(defun aij (a i j)
  (nth i (nth j a))
  )

(defun len (l)
(if (atom l) 
    0
      (+ (len (cdr l)) 1))
)

(defun range (a b d)
  (if (eql a b)
        (list a)
	      (cons a (range (+ a d) b))
	        )
  )

(defun xrange (a b x)
	(if (eql a b)
		(list (list a x))
		(cons (list a x) (xrange (+ a 1) b x))
	)
)

(defun xyrange (a b c d)
	(if (eql c d)
		(list (xrange a b c))
		(cons (xrange a b c) (xyrange a b (+ c 1) d))
	)
)

(defun range1 (a b)
	(range a b 1)
)

(defun zeros (n)
	(if (eql n 1)
		(list 0)
		(cons 0 (zeros (- n 1)))
	)
)

(defun rowij (l i j)
	;(format t "(rowij ~d ~d ~d)=" l i j)
	(setq res (zeros l))
	(setf (nth i res) 1)
	(setf (nth j res) 1)
	(list res)
)



;(adjacency matrix to incidence matrix)

(setq m '( (0 1 0) (0 0 1) (1 1 0)))


(defun a2i (m)
	(setq n (len m))
	(setq mainres '())
	(defun yieldij (i j)
		(if (eql (aij m i j) 1)
			(setq mainres (append mainres (rowij n i j)))
			(setq mainres (append mainres (list (zeros n))))
		)
	)
	(defun yield (x)
		(yieldij (car x) (cadr x))
	)
	(defun yieldrow (l)
		(map 'list 'yield l)
	)
	(setq iterator (xyrange 0 (- n 1) 0 (- n 1)))
	(map 'list 'yieldrow iterator)
	mainres
)
(print m)
(print (a2i m))
